package com.gzw.dms.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;


import com.gzw.dms.R;
import com.gzw.dms.bean.City_Info;

import java.util.HashMap;
import java.util.List;

/**
 * 作者： Wdx on 2016/8/12.
 * 邮箱： 18604454731@163.com
 * 作用：
 */
public class CountyAdapter extends BaseAdapter {
    private Context context;
    private int position = 0;
    private static HashMap<Integer,Boolean> isSelected;
    private List<City_Info> lists;

    public CountyAdapter(Context context, List<City_Info> lists) {
        this.context = context;
        this.lists = lists;
        isSelected = new HashMap<Integer,Boolean>();
        initDate();
    }

    private void initDate() {
        for (int i = 0; i < lists.size(); i++) {
            getIsSelected().put(i, false);
        }
    }

    public int getCount() {
        return lists.size();
    }

    public Object getItem(int position) {
        return lists.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder hold = null;
        if (convertView == null) {
            hold = new Holder();
            convertView = View.inflate(context , R.layout.item_gridview , null);
            hold.checkBox = (CheckBox) convertView.findViewById(R.id.gridview_check);
            convertView.setTag(hold);
        } else {
            hold = (Holder) convertView.getTag();
        }
        hold.checkBox.setText(lists.get(position).getCityname());

        hold.checkBox.setOnCheckedChangeListener(null);

        return convertView;
    }


    public void setSelectItem(int position) {
        this.position = position;
    }

    public static class Holder {
        public CheckBox checkBox;
    }

    public static HashMap<Integer,Boolean> getIsSelected() {
        return isSelected;
    }
    public static void setIsSelected(HashMap<Integer,Boolean> isSelected) {
        CountyAdapter.isSelected = isSelected;
    }
}
